import React, { useState } from 'react';
import { DatePicker, List } from 'antd-mobile';
import Star from '../star';
import './index.less';

export default function TimePicker(props) {
  const date = new Date();
  const year = date.getFullYear();
  const month = date.getMonth();
  const day = date.getDate();
  const hour = date.getHours();
  const minute = date.getMinutes();
  const second = date.getSeconds();
  const { handleOnChange, label, field } = props;
  const [time, setTime] = useState('');
  function handleTimeChange(v) {
    setTime(v);
    handleOnChange(v, label, field && field);
  }
  return (
    <div className="timePicker">
      <Star />
      <DatePicker
        value={time}
        onChange={handleTimeChange}
        minDate={new Date(year, month, day, hour, minute, second)}
      >
        <List.Item arrow="horizontal">选择失效日期</List.Item>
      </DatePicker>
    </div>
  );
}
